package com.example.springbootquartz.quartz.MyTask;

import com.example.springbootquartz.entity.SysJob;
import com.example.springbootquartz.service.SysJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author fulin
 * @since 2023/6/14 15:57
 * <p>
 * 此类作为具体执行任务的示例类
 * 此类应该注入spring容器中,为了后去获取方便,且一般业务都需要查询数据,所以此类比较常见
 * 如果非bean,那么 {@link com.example.springbootquartz.quartz.QuartzJob}.中需要自己扩展获取目标类 利用Class.forName()
 * </p>
 */
@Service("task")
public class MyTask {

    @Autowired
    SysJobService sysJobService;

    /**
     * 任务的具体执行逻辑写在此处,这里只做打印
     */
    public void sout() {
        List<SysJob> list = sysJobService.list();
        list.forEach(sysJob -> System.out.println(sysJob.toString()));
    }
}
